home *** CD-ROM | disk | FTP | other *** search
- #include <conio.h>
- #include <dos.h>
- #include <mem.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <time.h>
-
- #include "ytypes.hpp"
- #include "yprim.hpp"
- #include "ypal.hpp"
- #include "yblitbuf.hpp"
- #include "fixed32.hpp"
-
- #define MAXLINE 100000L
-
- #define BUDDHA_DEMO 1
- #define FIRE_DEMO 1
- #define MONSTER_DEMO_ONE 1
- #define MONSTER_DEMO_TWO 1
-
-
- int gbuddha;
-
- int
- buddha_demo(void)
- {
- clock_t begin, end;
- Iangle theta1, theta2;
- Fixed32 trigSin, trigCos;
- long count, y;
- blitbuf blit_image, sprite_image;
- BYTE *ptr1;
- BYTE *ptr2;
-
- clear(0);
- load_blitbufPCX("buddha.pcx", &sprite_image);
- scale_blitbuf(152, 168, &sprite_image);
- alloc_blitbuf(&blit_image, 152, 168);
-
- // 152x168 image
- bitblit(84, 16, &sprite_image);
- getch();
-
- initFixed32();
-
- theta1=0;
- count=0;
-
- begin = clock();
-
- while (!kbhit()) {
- ptr1 = sprite_image.image;
- ptr2 = blit_image.image;
- theta2 = theta1;
-
- y=168;
- while (y--) {
- CosSin(theta2, &trigCos, &trigSin);
- scale_scanline(ptr1, ptr2, 152, 152, (trigCos >> 10) + 88);
- #if 1
- memcpy(ptr2+152, ptr2, 152);
- ptr1 += 304;
- ptr2 += 304;
- theta2 += 4;
- y--;
- #else
- ptr1 += 152;
- ptr2 += 152;
- theta2 += 2;
- #endif
- }
-
- theta1 += 2;
-
- bitblit(84, 16, &blit_image);
- count++;
- }
-
- end = clock();
-
- getch();
-
- clear_blitbuf(&blit_image);
- clear_blitbuf(&sprite_image);
-
- gbuddha = count;
-
- return (end - begin);
- }
-
-
- void
- fire_demo(void)
- {
- #define V_WIDTH 80
- #define V_HEIGHT 50
- #define BUF_WIDTH 80
- #define BUF_HEIGHT 56
- #define REWIND (320 * 3)
- #define BUF_SIZE (BUF_WIDTH * BUF_HEIGHT)
-
- unsigned char fire_pal[768] = {
- 0, 0, 0, 0, 0, 24, 0, 0, 24, 0, 0, 28,
- 0, 0, 32, 0, 0, 32, 0, 0, 36, 0, 0, 40,
- 8, 0, 40, 16, 0, 36, 24, 0, 36, 32, 0, 32,
- 40, 0, 28, 48, 0, 28, 56, 0, 24, 64, 0, 20,
- 72, 0, 20, 80, 0, 16, 88, 0, 16, 96, 0, 12,
- 104, 0, 8, 112, 0, 8, 120, 0, 4, 128, 0, 0,
- 128, 0, 0, 132, 0, 0, 136, 0, 0, 140, 0, 0,
- 144, 0, 0, 144, 0, 0, 148, 0, 0, 152, 0, 0,
- 156, 0, 0, 160, 0, 0, 160, 0, 0, 164, 0, 0,
- 168, 0, 0, 172, 0, 0, 176, 0, 0, 180, 0, 0,
- 184, 4, 0, 188, 4, 0, 192, 8, 0, 196, 8, 0,
- 200, 12, 0, 204, 12, 0, 208, 16, 0, 212, 16, 0,
- 216, 20, 0, 220, 20, 0, 224, 24, 0, 228, 24, 0,
- 232, 28, 0, 236, 28, 0, 240, 32, 0, 244, 32, 0,
- 252, 36, 0, 252, 36, 0, 252, 40, 0, 252, 40, 0,
- 252, 44, 0, 252, 44, 0, 252, 48, 0, 252, 48, 0,
- 252, 52, 0, 252, 52, 0, 252, 56, 0, 252, 56, 0,
- 252, 60, 0, 252, 60, 0, 252, 64, 0, 252, 64, 0,
- 252, 68, 0, 252, 68, 0, 252, 72, 0, 252, 72, 0,
- 252, 76, 0, 252, 76, 0, 252, 80, 0, 252, 80, 0,
- 252, 84, 0, 252, 84, 0, 252, 88, 0, 252, 88, 0,
- 252, 92, 0, 252, 96, 0, 252, 96, 0, 252, 100, 0,
- 252, 100, 0, 252, 104, 0, 252, 104, 0, 252, 108, 0,
- 252, 108, 0, 252, 112, 0, 252, 112, 0, 252, 116, 0,
- 252, 116, 0, 252, 120, 0, 252, 120, 0, 252, 124, 0,
- 252, 124, 0, 252, 128, 0, 252, 128, 0, 252, 132, 0,
- 252, 132, 0, 252, 136, 0, 252, 136, 0, 252, 140, 0,
- 252, 140, 0, 252, 144, 0, 252, 144, 0, 252, 148, 0,
- 252, 152, 0, 252, 152, 0, 252, 156, 0, 252, 156, 0,
- 252, 160, 0, 252, 160, 0, 252, 164, 0, 252, 164, 0,
- 252, 168, 0, 252, 168, 0, 252, 172, 0, 252, 172, 0,
- 252, 176, 0, 252, 176, 0, 252, 180, 0, 252, 180, 0,
- 252, 184, 0, 252, 184, 0, 252, 188, 0, 252, 188, 0,
- 252, 192, 0, 252, 192, 0, 252, 196, 0, 252, 196, 0,
- 252, 200, 0, 252, 200, 0, 252, 204, 0, 252, 208, 0,
- 252, 208, 0, 252, 208, 0, 252, 208, 0, 252, 208, 0,
- 252, 212, 0, 252, 212, 0, 252, 212, 0, 252, 212, 0,
- 252, 216, 0, 252, 216, 0, 252, 216, 0, 252, 216, 0,
- 252, 216, 0, 252, 220, 0, 252, 220, 0, 252, 220, 0,
- 252, 220, 0, 252, 224, 0, 252, 224, 0, 252, 224, 0,
- 252, 224, 0, 252, 228, 0, 252, 228, 0, 252, 228, 0,
- 252, 228, 0, 252, 228, 0, 252, 232, 0, 252, 232, 0,
- 252, 232, 0, 252, 232, 0, 252, 236, 0, 252, 236, 0,
- 252, 236, 0, 252, 236, 0, 252, 240, 0, 252, 240, 0,
- 252, 240, 0, 252, 240, 0, 252, 240, 0, 252, 244, 0,
- 252, 244, 0, 252, 244, 0, 252, 244, 0, 252, 248, 0,
- 252, 248, 0, 252, 248, 0, 252, 248, 0, 252, 252, 0,
- 252, 252, 4, 252, 252, 8, 252, 252, 12, 252, 252, 16,
- 252, 252, 20, 252, 252, 24, 252, 252, 28, 252, 252, 32,
- 252, 252, 36, 252, 252, 40, 252, 252, 40, 252, 252, 44,
- 252, 252, 48, 252, 252, 52, 252, 252, 56, 252, 252, 60,
- 252, 252, 64, 252, 252, 68, 252, 252, 72, 252, 252, 76,
- 252, 252, 80, 252, 252, 84, 252, 252, 84, 252, 252, 88,
- 252, 252, 92, 252, 252, 96, 252, 252, 100, 252, 252, 104,
- 252, 252, 108, 252, 252, 112, 252, 252, 116, 252, 252, 120,
- 252, 252, 124, 252, 252, 124, 252, 252, 128, 252, 252, 132,
- 252, 252, 136, 252, 252, 140, 252, 252, 144, 252, 252, 148,
- 252, 252, 152, 252, 252, 156, 252, 252, 160, 252, 252, 164,
- 252, 252, 168, 252, 252, 168, 252, 252, 172, 252, 252, 176,
- 252, 252, 180, 252, 252, 184, 252, 252, 188, 252, 252, 192,
- 252, 252, 196, 252, 252, 200, 252, 252, 204, 252, 252, 208,
- 252, 252, 208, 252, 252, 212, 252, 252, 216, 252, 252, 220,
- 252, 252, 224, 252, 252, 228, 252, 252, 232, 252, 252, 236,
- 252, 252, 240, 252, 252, 244, 252, 252, 248, 252, 252, 252
- };
-
- unsigned char *screen;
- unsigned char *flamebuf_ptr;
- unsigned char *flamebuf;
- unsigned char temp;
- unsigned short int i, j, skip;
- unsigned char temp_byte;
- unsigned char line_buf[320];
- unsigned char *line_buf_ptr;
-
- set_palette(fire_pal);
- flamebuf = new unsigned char[BUF_SIZE];
- skip = 320 - 3;
-
- // Initialize the video buffer to 0's
- memset(flamebuf, 0, BUF_SIZE);
-
- while (!kbhit()) {
- // Transform current buffer
- flamebuf_ptr = flamebuf;
- i = (BUF_HEIGHT - 2);
- while (i--) {
- *flamebuf_ptr = (*(flamebuf_ptr + BUF_WIDTH) +
- *(flamebuf_ptr + (BUF_WIDTH - 1)) +
- *(flamebuf_ptr + (BUF_WIDTH + 1)) +
- *(flamebuf_ptr + (BUF_WIDTH * 2))) >> 2;
-
- flamebuf_ptr += BUF_WIDTH;
- temp = *flamebuf_ptr;
- if (temp > 11) {
- *flamebuf_ptr -= 12;
- } else if (temp > 3) {
- *flamebuf_ptr -= 4;
- } else {
- *flamebuf_ptr = 0;
- }
- flamebuf_ptr += (1 - BUF_WIDTH);
-
- j = (BUF_WIDTH - 2);
- while (j--) {
- *flamebuf_ptr = (*(flamebuf_ptr + BUF_WIDTH) +
- *(flamebuf_ptr + (BUF_WIDTH - 1)) +
- *(flamebuf_ptr + (BUF_WIDTH + 1)) +
- *(flamebuf_ptr + (BUF_WIDTH * 2))) >> 2;
-
- flamebuf_ptr += BUF_WIDTH;
- temp = *flamebuf_ptr;
- if (temp > 11) {
- *flamebuf_ptr -= 12;
- } else if (temp > 3) {
- *flamebuf_ptr -= 4;
- } else {
- *flamebuf_ptr = 0;
- }
- flamebuf_ptr += (1 - BUF_WIDTH);
- }
-
- *flamebuf_ptr = (*(flamebuf_ptr + BUF_WIDTH) +
- *(flamebuf_ptr + (BUF_WIDTH - 1)) +
- *(flamebuf_ptr + (BUF_WIDTH * 2)) +
- *(flamebuf_ptr + (BUF_WIDTH * 2) +
- (BUF_WIDTH - 1))) >> 2;
-
- flamebuf_ptr += BUF_WIDTH;
- temp = *flamebuf_ptr;
- if (temp > 11) {
- *flamebuf_ptr -= 12;
- } else if (temp > 3) {
- *flamebuf_ptr -= 4;
- } else {
- *flamebuf_ptr = 0;
- }
- flamebuf_ptr += (1 - BUF_WIDTH);
- }
-
- // Set new bottom line with random white or black
- temp = 0;
- flamebuf_ptr = flamebuf + (BUF_WIDTH * (BUF_HEIGHT - 2));
-
- j = BUF_WIDTH;
- temp = 0;
- while (j--) {
- // We change the value 1/4 of the time
- if ((rand() & 0x03) == 3) {
- temp = (255 - temp);
- }
-
- *(flamebuf_ptr + BUF_WIDTH) = temp;
- *flamebuf_ptr++ = temp;
- }
-
- // Write the buffer to the screen
- screen = RowsY[0];
- flamebuf_ptr = flamebuf;
- // wait_for_retrace();
- i = V_HEIGHT;
- while (i--) {
- j = V_WIDTH;
- line_buf_ptr = line_buf;
- while (j--) {
- temp_byte = *flamebuf_ptr++;
- *line_buf_ptr++ = temp_byte;
- *line_buf_ptr++ = temp_byte;
- *line_buf_ptr++ = temp_byte;
- *line_buf_ptr++ = temp_byte;
- }
-
- memcpy(screen, line_buf, 320);
- screen += 320;
- memcpy(screen, line_buf, 320);
- screen += 320;
- memcpy(screen, line_buf, 320);
- screen += 320;
- memcpy(screen, line_buf, 320);
- screen += 320;
- }
- }
-
- getch();
-
- delete flamebuf;
- }
-
-
- int
- monster_demo1(void)
- {
- clock_t begin, end;
- short int i;
- blitbuf sprite_image, blit_image;
-
- clear(0);
-
- load_blitbufPCX("monster.pcx", &sprite_image);
- bitblit(0, 0, &sprite_image);
- getch();
-
- blit_image.image = NULL;
-
- i=99;
-
- begin = clock();
-
- while (i > 0) {
- scale_blitbuf(120 + (i << 1), (i << 1), &sprite_image, &blit_image);
- box((99 - i), (99 - i), (220 + i), (100 + i), 0);
- bitblit(100 - i, 100 - i, &blit_image);
- i--;
- }
-
- end = clock();
-
- i=120;
- while (i > 0) {
- scale_blitbuf(i, 2, &sprite_image, &blit_image);
-
- putpixel(159 - (i >> 1), 99, 0);
- putpixel(159 - (i >> 1), 100, 0);
- putpixel(160 + (i >> 1), 99, 0);
- putpixel(160 + (i >> 1), 100, 0);
-
- bitblit(160 - (i >> 1), 99, &blit_image);
- delay(5);
- i -= 2;
- }
-
- filledbox(156, 99, 163, 100, 0);
- putpixel(159, 100, 1);
- delay(250);
- putpixel(159, 100, 0);
-
- filledbox(156, 99, 163, 120, 0);
- clear_blitbuf(&sprite_image);
- clear_blitbuf(&blit_image);
-
- getch();
-
- return (end - begin);
- }
-
-
- void
- monster_demo2(void)
- {
- short int i;
- blitbuf sprite_image, blit_image;
-
- clear(0);
-
- load_blitbufPCX("monster.pcx", &sprite_image);
- bitblit(0, 0, &sprite_image);
- getch();
-
- blit_image.image = NULL;
-
- i=99;
- while (i) {
- vertical_scale_blitbuf((i << 1), &sprite_image, &blit_image);
- box(0, (99 - i), 319, (100 + i), 0);
- bitblit(0, 100 - i, &blit_image);
- i--;
- }
-
- filledbox(0, 100, 319, 100, 0);
-
- i=318;
- while (i > 0) {
- scale_blitbuf(i, 1, &blit_image, &sprite_image);
-
- putpixel(159 - (i >> 1), 99, 0);
- putpixel(159 - (i >> 1), 100, 0);
- putpixel(160 + (i >> 1), 99, 0);
- putpixel(160 + (i >> 1), 100, 0);
-
- bitblit(160 - (i >> 1), 99, &sprite_image);
- delay(5);
- i -= 2;
- }
-
- filledbox(156, 99, 163, 100, 0);
- putpixel(159, 100, 1);
- delay(250);
- putpixel(159, 100, 0);
- filledbox(156, 99, 163, 100, 0);
- clear_blitbuf(&sprite_image);
- clear_blitbuf(&blit_image);
-
- getch();
- }
-
-
- void
- main(void)
- {
- clock_t begin, end;
- long i, j, x1, x2, y1, y2, mtime, btime;
- long time1, time2;
-
- set320x200x256();
-
- loadfont("vga8x8.fnt");
-
- for (i=0; i < 320; i++) {
- for (j=0; j < 200; j++) {
- putpixel(i, j, (i & 0xFF));
- }
- }
-
- getch();
-
- clear(0);
-
- begin = clock();
-
- for (i=0; i < MAXLINE; i++) {
- x1 = rand() % 320;
- x2 = rand() % 320;
- y1 = rand() % 200;
- y2 = rand() % 200;
-
- line(x1, y1, x2, y2, (i & 0xFF));
- }
-
- end = clock();
- time1 = (end - begin);
-
- getch();
-
- begin = clock();
-
- for (i=0; i < MAXLINE; i++) {
- x1 = rand() % 320;
- x2 = rand() % 320;
- y1 = rand() % 200;
- y2 = rand() % 200;
-
- x1 = (i & 0xFF);
- }
-
- end = clock();
- time2 = (end - begin);
-
- #if BUDDHA_DEMO
- clear(0);
- btime = buddha_demo();
- #endif
-
- #if FIRE_DEMO
- clear(0);
- fire_demo();
- #endif
-
- #if MONSTER_DEMO_ONE
- mtime = monster_demo1();
- #endif
-
- #if MONSTER_DEMO_TWO
- monster_demo2();
- #endif
-
- putstring(0,0,"BYE!", 1);
-
- getch();
-
- set80x25();
-
- printf("%ld lines took %4d ticks\n", MAXLINE, time1);
- printf("rand() overhead = %4d ticks\n", time2);
- printf("Time in lineY = %4d ticks\n", (time1 - time2));
- printf("%d lines per second!\n\n", (MAXLINE * 1000) /
- (55 * (time1 - time2)));
-
- printf("Buddha = %4d blits\n", gbuddha);
- printf(" = %4d per second\n", (gbuddha * 1000) / (55 * btime));
- printf("Buddha = %4d scanline stretches\n", (gbuddha * 168));
- printf(" = %4d per second!\n\n", (gbuddha * 168000) / (55 * btime));
- }
-
-